﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;

//Write a program that, for a given two integer numbers N and X, calculates the sumS = 1 + 1!/X + 2!/X^2 + … + N!/X^N.


namespace _06FactorialDivByPower
{
    class _06FactorialDivByPower
    {
        static void Main(string[] args)
        {
            Console.Write("Enter values for N and X such that S = 1 + 1!/X + 2!/X^2 + … + N!/X^N.\nEnter value for N = ");
            string strN = Console.ReadLine();
            Decimal valueN = Decimal.Parse(strN);
            Console.Write("Enter value for X = ");
            string strX = Console.ReadLine();
            Decimal valueX = Decimal.Parse(strX);
            Decimal total = 1;
            Decimal factorialN = 1;
            Decimal xToPowerN = 1;
            while (valueN > 0)
            {
                factorialN = factorialN * valueN;
                xToPowerN = xToPowerN * valueX;
                total = total + factorialN / xToPowerN;
                valueN--;
            }
            Console.WriteLine("X^N = " + xToPowerN);
            Console.WriteLine("N! = " + factorialN);
            Console.WriteLine("S = " + total);
            Console.ReadLine();
        }
    }
}
